import { Session } from "@/utils/storage";

const DRAWING_ITEMS = "drawingItems";
const DRAWING_ID = "idGlobal";
const TREE_NODE_ID = "treeNodeId";
const FORM_CONF = "formConf";
const TableFields = "tableFields";
const SubTable = "subTable";
const AllTable = "allTable";
const HasTable = "hasTable";

export const getDrawingList = () => {
  const str = Session.get(DRAWING_ITEMS) as string;
  if (!["undefined", "null"].includes(str)) return JSON.parse(str);
  return null;
};

export const saveDrawingList = (list: any[]) => {
  Session.set(DRAWING_ITEMS, JSON.stringify(list));
};

export const getIdGlobal = () => {
  const str = Session.get(DRAWING_ID) as string;
  if (+str) return parseInt(str, 10);
  return 100;
};

export const saveIdGlobal = (id: any) => {
  Session.set(DRAWING_ID, `${id}`);
};

export const getTreeNodeId = () => {
  const str = Session.get(TREE_NODE_ID);
  if (str) return parseInt(str, 10);
  return 100;
};

export const saveTreeNodeId = (id: any) => {
  Session.set(TREE_NODE_ID, `${id}`);
};

export const getFormConf = () => {
  const str = Session.get(FORM_CONF);
  if (str) return JSON.parse(str);
  return null;
};

export const saveFormConf = (obj: any) => {
  Session.set(FORM_CONF, JSON.stringify(obj));
};

//数据表字段信息
export const saveTableFields = (list: any[]) => {
  Session.set(TableFields, list);
};
export const getTableFields = () => {
  return Session.get(TableFields);
};

//子表
export const saveSubTable = (tableList: any[]) => {
  Session.set(SubTable, tableList);
};

export const getSubTable = () => {
  return Session.get(SubTable);
};

//所有表
export const saveAllTable = (tableList: any[]) => {
  Session.set(AllTable, tableList);
};

export const getAllTable = () => {
  return Session.get(AllTable);
};

//是否有数据表
export const saveHasTable = (val: boolean) => {
  Session.set(HasTable, val);
};

export const getHasTable = () => {
  return Session.get(HasTable);
};
// export const Save_RELATION_DATA=(val:any)=> {
//   state.relationData = val
// }
